import { getAssistantList, getAssistantDel, postAssistantAdd } from '@/services/digitalEmployees'

export default {
    namespace: 'digitalEmployees',
    state: {
        data: {
            qaList: [],
            total: 0,
            suggestList: [],
        },
    },

    effects: {
        *fetchRobotList({ payload, callback }, { call, put }) {
            const response = yield call(getAssistantList, payload);
            if (callback && typeof callback === 'function') {
                callback(response);
            }
            yield put({
                type: 'save',
                payload: response,
            });
        },
        *fetchRobotRemove({ payload, callback }, { call, put }) {
            const response = yield call(getAssistantDel, payload);
            if (callback && typeof callback === 'function') {
                callback(response);
            }
            yield put({
                type: 'save',
                payload: response,
            });
        },
        *fetchRobotAdd({ payload, callback }, { call, put }) {
            const response = yield call(postAssistantAdd, payload);
            if (callback && typeof callback === 'function') {
                callback(response);
            }
            yield put({
                type: 'save',
                payload: response,
            });
        },
    },

    reducers: {
        save(state, { payload }) {
            return {
                ...state,
                ...payload,
            };
        },
    },
};
